package com.kaitian.demo.demo_boot_starter.exception;

import com.kaitian.demo.demo_boot_starter.vo.ResponseVO;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.security.auth.message.AuthException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author ：xietian
 * @version ：V1.0
 * @program ：demo
 * @date ：Created in 2022/4/11 16:31
 * @description ：统一的异常处理器, Rest控制器的通知类
 */
@RestControllerAdvice
public class GlobalExceptionAdvice {

    // 同类型异常，可以使用相同的异常处理器
    @ExceptionHandler(value = {AuthException.class})
    public ResponseVO<Void> authException(HttpServletRequest request, final AuthException e, HttpServletResponse response) {
        return new ResponseVO<Void>();
    }

    @ExceptionHandler(value = Exception.class)
    public ResponseVO<Void> exception(HttpServletRequest request, final Exception e, HttpServletResponse response) {
        return new ResponseVO<Void>();
    }
}